## Create Figure 4

## Load packages
library(tidyverse)
library(data.table)


## Effects by vote share at 5 pp. increments
vote = c(seq(15, 100, 1))

## Load estimates and SEs
vote_dta = read.table("ldp_vote_probs.txt") %>%
  bind_cols(., vote) %>%
  rename(received_est = V2, received_se = V3,
         vote = ...5)

figure4 = vote_dta %>%
  mutate(upper = received_est + 1.96 * received_se,
         lower = received_est - 1.96 * received_se, group = 1) %>%
  ggplot(., aes(x = vote, 
                y = as.numeric(received_est), group = 1,
                ymin = lower, ymax = upper)) +
  geom_line(color = "black") +
  geom_ribbon(aes(x = vote), alpha = .2, fill = "gray50") +
  geom_hline(yintercept=0, linetype="dashed", color = "darkgray") +
  geom_vline(xintercept=50, linetype="dashed", color = "darkgray") +
  scale_y_continuous(breaks = c(0, 0.05, 0.10, 0.15), 
                     limits = c(0, 0.18)) +
  scale_x_continuous(labels = c("0%", "25%", "50%", "75%", "100%")) +
  labs(x = "Vote Share", y = "Pr(Received LDP Project)") +
  theme_bw() +
  theme(panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(),
        panel.background = element_rect(colour = "black"))

